package com.campol.extlogger;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.text.TextUtils;

public class ExtLogger {

	private static ExtLogger instance;
	private String currentMessage = "";
	private static SimpleDateFormat sdf;
	
	public static ExtLogger getInstance() {
		if (instance == null) {
			instance = new ExtLogger();
		}
		if (sdf == null) {
			sdf = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
		}
		return instance;
	}
	
	public void writeLog(Date date, String tag, String message) {
		String d = sdf.format(date);
		currentMessage += String.format("%s   %s   %s\n",d, tag, message);
	}
	
	public void commitLog() {
		if (TextUtils.isEmpty(currentMessage)) return;
		ExtStorageHelper.writePlainTextToSdCard(currentMessage);
	}
}
